package logic

import (
	"context"
	"hm-zero-mall/apps/user/rpc/internal/svc"
	"hm-zero-mall/apps/user/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserListLogic {
	return &GetUserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// GetUserList 获取用户列表
func (l *GetUserListLogic) GetUserList(in *pb.GetListByUserIdListRequest) (*pb.UserListResponse, error) {
	users, err := l.svcCtx.UserModel.FindList(l.ctx, "", "", in.UserIdList)
	if err != nil {
		return nil, err
	}

	var userList []*pb.UserInfo
	for _, user := range users {
		userList = append(userList, &pb.UserInfo{
			Id:         user.Id,
			Username:   user.Username,
			Password:   user.Password,
			Phone:      user.Phone,
			Status:     user.Status,
			CreateTime: user.CreateTime,
			UpdateTime: user.UpdateTime,
			DeleteTime: user.DeleteTime,
		})
	}
	return &pb.UserListResponse{UserList: userList}, nil
}
